package com.spark.launcher;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.spark.launcher.SparkLauncher;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Administrator on 2017/8/22.
 */
public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {

        String[] pareams = {"areapoint_info=8221;1;001;001001;001002"};


        SparkLauncher launcher = new SparkLauncher();
        launcher.setAppResource("/user/MLF/ckmcluster-jobServer.jar");
        launcher.setMainClass("com.trs.cluster.test.AreaPointAllTest");
        launcher.addAppArgs(pareams);
        launcher.setMaster("spark://mlf-analyze-01:7077");
        launcher.setConf(SparkLauncher.DRIVER_MEMORY, "512m");
        launcher.setConf(SparkLauncher.EXECUTOR_MEMORY, "512m");
        launcher.setConf(SparkLauncher.EXECUTOR_CORES, "4");

        Process process = launcher.launch();

        InputStream stdInput = process.getInputStream();
        InputStream errInput = process.getErrorStream();

        process.waitFor();

        dumpInput(stdInput);
        dumpInput(errInput);
        System.out.println("launcher over");
    }


    private static void dumpInput(InputStream input) throws IOException {
        String res = IOUtils.toString(input, "GBK");
        System.out.println(res);
    }
}
